summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/k_page_table_manager.h
blob: 4b0e034d040491469051798ba084901568a56136 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <atomic>

#include "core/hle/kernel/k_dynamic_resource_manager.h"
#include "core/hle/kernel/k_page_table_slab_heap.h"
#include "core/hle/kernel/k_typed_address.h"

namespace Kernel {

class KPageTableManager : public KDynamicResourceManager<impl::PageTablePage, true> {
public:
    using RefCount = KPageTableSlabHeap::RefCount;
    static constexpr size_t PageTableSize = KPageTableSlabHeap::PageTableSize;

public:
    KPageTableManager() = default;

    void Initialize(KDynamicPageManager* page_allocator, KPageTableSlabHeap* pt_heap) {
        m_pt_heap = pt_heap;

        static_assert(std::derived_from<KPageTableSlabHeap, DynamicSlabType>);
        BaseHeap::Initialize(page_allocator, pt_heap);
    }

    KVirtualAddress Allocate() {
        return KVirtualAddress(BaseHeap::Allocate());
    }

    RefCount GetRefCount(KVirtualAddress addr) const {
        return m_pt_heap->GetRefCount(addr);
    }

    void Open(KVirtualAddress addr, int count) {
        return m_pt_heap->Open(addr, count);
    }

    bool Close(KVirtualAddress addr, int count) {
        return m_pt_heap->Close(addr, count);
    }

    bool IsInPageTableHeap(KVirtualAddress addr) const {
        return m_pt_heap->IsInRange(addr);
    }

private:
    using BaseHeap = KDynamicResourceManager<impl::PageTablePage, true>;

    KPageTableSlabHeap* m_pt_heap{};
};

} // namespace Kernel